/**
 * create by young (young2f@outlook.com) on 2020/12/4
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    treeId: { type: String, _type: 'code', title: '目录编码', required: true },
    treeName: { type: String, _type: 'code', title: '收款条目', required: true, enableArea: [ 'detail' ] },
    code: { type: String, _type: 'code', title: '编码', required: true },
    orderCode: { type: String, _type: 'code', title: '单据编码', },
    accountCode: { type: String, _type: 'string', title: '帐号编码', required: true, enableArea: [ 'detail' ] },
    accountName: {
      type: String, _type: 'code', title: '户名', enableArea: [],
    },
    _accountName: {
      type: String, _type: 'string', title: '户名', enableArea: [ 'table', 'search', 'detail' ]
    },
    openingBank: { type: String, _type: 'string', title: '开户行', enableArea: [ 'table', 'search', 'detail' ] },
    account: { type: String, _type: 'string', title: '账号', enableArea: [ 'table', 'search', 'detail' ] },
    balance: { type: Number, _type: 'number', title: '上月结余', enableArea: [ 'table', 'search', 'detail' ], },
    // division: {
    //   type: String,
    //   _type: 'code',
    //   title: '收入公司',
    //   required: true,
    //   enableArea: [ 'table', 'search', 'detail' ]
    // },
    date: { type: Date, _type: 'date', title: '日期', required: true, enableArea: [ 'table', 'search', 'detail' ] },
    origin: {
      type: String,
      _type: 'string',
      title: '收入来源',
      key: 'origin',
      enableArea: [ 'table', 'search', 'detail' ]
    },//付款人（人员，公司）\放款银行
    customerCode: {
      type: String,
      _type: 'string',
      title: '客户编码',
      key: 'customerCode',
      enableArea: [ ]
    },//付款人（人员，公司）\放款银行
    receiptMatter: {
      type: String,
      _type: 'string',
      title: '收入事由',
      key: 'matter',
      enableArea: [ 'table', 'search', 'detail' ]
    },
    receiptSalesman: {
      type: String,
      _type: 'string',
      title: '经办人',
      key: 'salesman',
      enableArea: [ 'table', 'search', 'detail' ]
    },
    receiptWay: {
      type: String, _type: 'select', title: '收款方式', key: 'receiptWay',
      options: [ '现金/个人户', '电汇/公户', '银承', '商承' ],
      enableArea: [ 'search', 'table', 'detail' ]
    },
    receiptAmount: {
      type: Number,
      _type: 'number',
      title: '收入金额',
      key: 'amount',
      enableArea: [ 'table', 'detail' ]
    },
    taxRate: {
      type: String, _type: 'string', title: '税率', enableArea: [
        'detail','table',
      ], default: '13%'
    },
    tax: {
      type: 'number', _type: 'code', title: '税额', enableArea: [
        'detail'
      ], default: 0
    },
    fileList: { type: Array, _type: 'fileList', title: '附件' },

    memo: { type: String, _type: 'string', title: '备注', enableArea: [ 'detail' ] },
    isEnd: {
      type: String,
      _type: 'select',
      title: '结单状态',
      tag: { '已结单': '#87d068', '未结单': '#108ee9' },
      default: '未结单',
      enableArea: [ 'search', 'table', 'detail' ],
      options: [ '未结单', '已结单' ]
    },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('Receipt', _schema);
};
